//package com.xucy.springboot.shiro;
//
//import org.apache.shiro.authc.*;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.springframework.util.CollectionUtils;
//
//import java.util.ArrayList;
//import java.util.HashSet;
//import java.util.List;
//import java.util.Set;
//
///**
// * @Author xucy
// * @Date 2019-09-01 17:01
// * @Description
// **/
//
//public class AuthRealm extends AuthorizingRealm {
//
//    //授权
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
//
//        User user=(User) principalCollection.fromRealm(this.getClass().getName()).iterator().next();
//        Set<Role> roles = user.getRoles();
//        List<String> permissionList=new ArrayList<>();
//        if(!CollectionUtils.isEmpty(roles)){
//            for(Role role:roles){
//                Set<Permission> permissions = role.getPermissions();
//                if(!CollectionUtils.isEmpty(permissions)){
//                   for(Permission permission:permissions){
//                       permissionList.add(permission.getPermissionName());
//                   }
//                }
//            }
//        }
//        SimpleAuthorizationInfo simpleAuthorizationInfo=new SimpleAuthorizationInfo();
//        simpleAuthorizationInfo.addStringPermissions(permissionList);
//        return simpleAuthorizationInfo;
//    }
//
//    //登陆
//    @Override
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//        UsernamePasswordToken usernamePasswordToken= (UsernamePasswordToken) authenticationToken;
//        Permission permission=new Permission();
//        permission.setPermissionName("add");
//
//        Set<Permission> permissionSet=new HashSet<>();
//        permissionSet.add(permission);
//
//        Role role=new Role();
//        role.setPermissions(permissionSet);
//
//        Set<Role> roleSet=new HashSet<>();
//        roleSet.add(role);
//
//
//
//        String username = usernamePasswordToken.getUsername();
//        User user=new User();
//        user.setUsername(username);
//        user.setPassword("12345");
//        user.setRoles(roleSet);
//        return new SimpleAuthenticationInfo(user,"12345",this.getClass().getName());
//    }
//}
